extends bag
class_name EquipmentBag
@onready var Epuipment_SlotManager = $Equipment_slot_manager

var Epuiment_array:Array#储存装备栏的节点
# Called when the node enters the scene tree for the first time.
func _ready():
	bag_name="E_bag"
	bag_grid_container.columns=bag_columns
	set_columns()
	initBag()
	pass

func initBag():
	# 初始化背包中的格子,将背包中的物品绘制到格子中
	var _Itemindex:int = 0
	var _Null_ItemInfo_Array:Array #记录没有东西的格子
	for slot in Epuipment_SlotManager.get_children():
		var c = slot
		c.mouse_slot = mouse_slot
		c.bag_name = bag_name
		Epuiment_array.append([c])

## 购买后自动装备
func add_item(item: Dictionary, item_stats: PandoraEntity) -> bool:
	for slot in Epuipment_SlotManager.get_children():
		if slot.item_info_dict.is_empty():
			slot.item_info_dict = item
			slot.item_pandora = item_stats
			Utils.add_to_player(slot.item_pandora)
			return true

	return false

## 尝试合成
func synthesis(item_stats: PandoraEntity) -> bool:
	for slot in Epuipment_SlotManager.get_children():
		if not slot.item_info_dict.is_empty():
			var dict = {}
			dict.get_or_add(slot.item_pandora.get_entity_id())
			dict.get_or_add(item_stats.get_entity_id())
			var recipe = ItemManager.recipe_book.find_recipe(dict)
			if recipe != null:
				Utils.minus_to_player(slot.item_pandora)
				var target = Pandora.get_entity(recipe.target_id)
				slot.item_pandora = null
				slot.item_info_dict = {}
				EventBus.push_event("add_item", [target])
				#Utils.add_to_player(slot.item_pandora)
				return true
	return false
